<?python
	from whatwhat.model import STATUS_BEHIND_SCHEDULE
	from whatwhat.utils import textilize
  
	def get_display_notes(project, show_all_notes):
		if show_all_notes:
			return project.notes
		return project.recent_notes
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
    py:extends="'../master.kid'">

<head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
    <title>WhatWhat Status - Project Details for ${project.name}</title>
	<script src="/static/javascript/master.js" type="text/javascript"></script>
	<script src="/static/javascript/project.js" type="text/javascript"></script>
    <script src="/static/javascript/thirdparty/prototype.js" type="text/javascript"></script>
    <script src="/static/javascript/thirdparty/scriptaculous.js" type="text/javascript"></script>
    <script src="/static/javascript/thirdparty/effects.js" type="text/javascript"></script>
    <script src="/static/javascript/thirdparty/slider.js" type="text/javascript"></script>
     <script src="/static/javascript/thirdparty/builder.js" type="text/javascript"></script>
      <script src="/static/javascript/thirdparty/controls.js" type="text/javascript"></script>
    
	<script>
		function check_note_length(note){
			
			var note = document.getElementById(note);
			
			if (note.value.length >= 1500) {
				alert('Please use separate notes for lengthy posts');
				note.focus();
				return false;
			}
	
			return true;
		}
	</script>
	
	<link href="/static/css/master.css" media="screen" rel="Stylesheet" type="text/css" /> 
	<link href="/static/css/project.css" media="screen" rel="Stylesheet" type="text/css" />
</head>

<body>	
	<h2 id="project_name" py:content="project.name">Project Name</h2>
	
	<div py:if="project.contact == user_person or 'admin' in groupids" id="status">
		<select id="project_status" py:if="not project.archived" name="status" onchange="update_project(); return false;">
			<option py:for="status in status_codes.keys()" value="$status" selected="${(None, '')[status == project.status]}">
				${status_codes[status]}
			</option>
		</select>
		<span py:if="project.archived">Archived</span>
		<br/>
	</div>
	<div class="bad" py:if="(project.contact != user_person and (not 'admin' in groupids)) and (project.status == STATUS_BEHIND_SCHEDULE)" id="status">
		${status_codes[project.status]}
	</div>
	<div class="good" py:if="(project.contact != user_person and (not 'admin' in groupids)) and (project.status != STATUS_BEHIND_SCHEDULE)" id="status">
		${status_codes[project.status]}
	</div>
	
	<div id="description" onmouseover="show_inline('description_edit_link')" onmouseout="hide('description_edit_link')">
		<span id="description_content">${XML(textilize(project.description))}</span>
		<a py:if="project.contact == user_person or 'admin' in groupids" style="display: none" id="description_edit_link" href="#" onclick="toggle('edit_description');toggle('description'); return false;">edit</a><br/>
	</div>
	
	<div id="edit_description" style="display: none;">
		<textarea id="ta_description" name="description" rows="3" cols="70">${project.description}</textarea><br/>
		<a href="#" onclick="update_project();toggle('edit_description');toggle('description');hide('description_edit_link');return false;">save</a>
		<a href="#" onclick="toggle('edit_description');toggle('description');hide('description_edit_link'); return false;">cancel</a>
	</div>
	
	<br/>
	
	<div id="contact" onmouseover="show_inline('edit_contact_link');" onmouseout="hide('edit_contact_link');">
		<b>Contact:</b>
		<span id="contact_content"><a href="mailto:$project.contact.emailAddress">${project.contact.displayName}</a></span>
		<a py:if="project.contact == user_person or 'admin' in groupids" style="display: none" id="edit_contact_link" href="#" onclick="toggle('contact');toggle('edit_contact'); return false;">edit</a>
	</div>
	
	<div style="display: none" id="edit_contact">
		<b>Contact:</b>
		<select id="contact_id" name="contact_id" onchange="update_project(); window.location.reload(); return false;">
			<option py:for="person in people" selected="${(None, '')[person == project.contact]}" value="$person.id">
				${person.displayName}
			</option>
		</select>
		<a href="#" onclick="toggle('edit_contact');toggle('contact');hide('edit_contact_link'); return false;">cancel</a>
	</div>
	
	<ul id="toggle_links">
		<li py:if="len(project.sub_projects) > 0"><a class="on" id="subprojects_switch" href="#" onclick="toggle('project_subprojects');switch_link('subprojects'); return false;">sub-projects</a></li>
		<li py:if="project.parent_project != None"><a class="on" id="parent_switch" href="#" onclick="toggle('project_parent');switch_link('parent'); return false;">parent project</a></li>
		<li><a class="on" id="issues_switch" href="#" onclick="toggle('project_issues');switch_link('issues'); return false;">issues</a></li>
		<li><a class="on" id="risks_switch" href="#" onclick="toggle('project_risks');switch_link('risks'); return false;">risks</a></li>
		<li><a class="on" id="notes_switch" href="#" onclick="toggle('project_notes');switch_link('notes'); return false;">progress notes</a></li>
		<li><a class="on" id="questions_switch" href="#" onclick="toggle('project_questions');switch_link('questions'); return false;">questions</a></li>
	</ul>
	
	<div id="project_subprojects" py:if="len(project.sub_projects) > 0">
		<h3>Sub Projects</h3>
		<ul id="subprojects">
			<li py:for="subproject in project.sub_projects">
				<a href="/project/$subproject.id">${subproject.name}</a> (${status_codes[subproject.status]})
			</li>
		</ul>
	</div>
	
	<div id="project_parent" py:if="project.parent_project != None">
		<h3>Parent Project</h3>
		This project is a sub-project of 
		<a href="/project/$project.parent_project.id">
			${project.parent_project.name}
		</a>.
	</div>
	
	<div id="project_issues">
		<h3>Issues</h3>
		<p py:if="len(project.open_issues) == 0">This project has no open issues.</p>
        <div id="issues_container" py:content="issues_widget.display(issues=project.issues, show_closed=show_closed_issues)" />
		
		<a href="#" onclick="toggle('new_issue');fcs('new_issue_description'); return false;">add issue</a>
		<form id="toggle_closed_issues" action="toggle_closed_issues" method="post"></form>
		<a py:if="show_closed_issues and len(project.issues)" href="#" onclick="submit('toggle_closed_issues'); return false;">hide closed issues</a>
		<a py:if="not show_closed_issues and len(project.issues)" href="#" onclick="submit('toggle_closed_issues'); return false;">show closed issues</a>
		
		<div id="new_issue" style="display: none;">
			<table>
				<tr>
					<td><b>Impact</b></td>
					<td>
						<select id="new_issue_impact" name="impact">
							<option py:for="impact in impact_codes.keys()" value="$impact">${impact_codes[impact]}</option>
						</select>
					</td>
				</tr>
			</table>
			<b>Description</b><br/>
			<textarea id="new_issue_description" name="description" rows="4" cols="70"></textarea><br/>
			<a href="#" onclick="add_issue(); return false;">add</a>
			<a href="#" onclick="toggle('new_issue'); return false;">cancel</a>
		</div>
	</div>
	
	<div id="project_risks">
		<h3>Risks</h3>
		<p py:if="len(project.open_risks) == 0">This project has no open risks.</p>
		<div id="risks_container" py:content="risks_widget.display(risks=project.risks, show_closed=show_closed_risks)" />
		
		<a href="#" onclick="toggle('new_risk');fcs('new_risk_description'); return false;">add risk</a>
		<form id="toggle_closed_risks" action="toggle_closed_risks" method="post"></form>
		<a py:if="show_closed_risks and len(project.risks)" href="#" onclick="submit('toggle_closed_risks'); return false;">hide closed risks</a>
		<a py:if="not show_closed_risks and len(project.risks)" href="#" onclick="submit('toggle_closed_risks'); return false;">show closed risks</a>
		
		<div id="new_risk" style="display: none;">
			<table>
				<tr>
					<td><b>Impact</b></td>
					<td>
						<select id="new_risk_impact" name="impact">
							<option py:for="impact in impact_codes.keys()" value="$impact">${impact_codes[impact]}</option>
						</select>
					</td>
					<td width="5"></td>
					<td><b>Chance</b></td>
					<td>
						<select id="new_risk_chance" name="chance">
							<option py:for="chance in chance_codes.keys()" value="$chance">${chance_codes[chance]}</option>
						</select>
					</td>
				</tr>
			</table>
			<b>Description</b><br/>
			<textarea id="new_risk_description" name="description" rows="4" cols="70"></textarea><br/>
			<a href="#" onclick="add_risk(); return false;">add</a>
			<a href="#" onclick="toggle('new_risk'); return false;">cancel</a>
		</div>
	</div>
	
	<div id="project_notes">
		<h3 py:if="show_all_notes">All Progress Notes</h3>
		<h3 py:if="not show_all_notes">Recent Progress Notes</h3>
		<p py:if="len(project.notes) == 0" id="no_notes_message">This project has no notes.</p>
		
        <span py:replace="notes_widget.display(notes=get_display_notes(project, show_all_notes), read_only=False)" />
		
		<a href="#" onclick="toggle('new_note'); fcs('ta_new_note'); return false;">add note</a>
		<a py:if="show_all_notes" href="#" onclick="submit('toggle_show_all_notes'); return false;">show recent notes</a>
		<a py:if="not show_all_notes" href="#" onclick="submit('toggle_show_all_notes'); return false;">show all notes</a>
		<form id="toggle_show_all_notes" action="toggle_show_all_notes" method="post" />
		
		<div id="new_note" style="display: none;">
		  <b>Note</b><br/>
          <textarea id="ta_new_note" name="note" rows="8" cols="70"></textarea><br/>
          <a href="#" onclick="if (check_note_length('ta_new_note')) {create_new_note();}; return false;">add</a>
          <a href="#" onclick="toggle('new_note'); return false;">cancel</a>
		</div>
	</div>
	
	<div id="project_questions">
		<h3>Questions</h3>
		
		<p py:if="len(project.questions) == 0">This project has no questions.</p>
		
        <span py:replace="questions_widget.display(questions=project.questions)" />
		
		<a href="#" onclick="toggle('new_question'); fcs('new_question_text'); return false;">ask question</a>
		<div id="new_question" style="display: none;">
			<b>Question</b><br/>
			<textarea id="new_question_text" name="question" rows="5" cols="80"></textarea><br/>
			<a href="#" onclick="add_question(); return false;">add</a>
			<a href="#" onclick="toggle('new_question'); return false;">cancel</a>
		</div>
	</div>
	
	
	<div id="project_files">
		<h3>Project Files</h3>
		<p py:if="len(project.files) == 0">This project has no files.</p>
		<ul id="files">
			<li class="file" py:for="file in project.files" onmouseover="show_inline('remove_file_link_$file.id');" onmouseout="hide('remove_file_link_$file.id'); ">
				<div class="file_content">
					<div><a href="javascript:void(0)" onclick="javascript:window.open('/static/files/$file.systemfilename', '', 'fullscreen=no,toolbar=yes,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no')">${file.filename}</a></div>
					<div class="file_info">
						<span>
						Posted by <a class="file_creator" href="mailto:$file.creator.emailAddress">${file.creator.displayName}</a> 
						on ${file.creation_date}
						</span>
						
						<a py:if="user_person == file.creator or 'admin' in groupids" style="display: none" id="remove_file_link_$file.id" href="#" class="remove_file_link" onclick="submit('remove_file_$file.id'); return false;">remove</a>
					</div>
				</div>
				<form action="remove_file" method="post" id="remove_file_$file.id">
					<input type="hidden" name="file_id" value="$file.id" />
				</form>
			</li>
		</ul>
		
		<a href="#" onclick="toggle('new_file'); fcs('ta_new_file'); return false;">add file</a>
		<div id="new_file" style="display: none;">
			<form id="form_new_file" action="new_file" method="post" enctype="multipart/form-data">
				<b></b><br/>
				Upload File: <input id="ta_new_file" name="file" type="file"/><br/>
				<a href="#" onclick="submit('form_new_file'); return false;">add</a>
				<a href="#" onclick="toggle('new_file'); return false;">cancel</a>
			</form>
		</div>
	</div>
	
	<div py:if="(user_person == project.contact or 'admin' in groupids) and (project.parent_project == None)" id="archive_project">
		<form py:if="not project.archived" id="form_archive" method="post" action="archive_project">
			<a href="#" onclick="submit('form_archive'); return false;">archive this project</a>
		</form>
		<form py:if="project.archived" id="form_unarchive" method="post" action="unarchive_project">		
			<a href="#" onclick="submit('form_unarchive'); return false;">unarchive this project</a>
		</form>
	</div>

</body>
</html>
